home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / DEMONSTR / ATEASY_2.ZIP / CDLL.C < prev    next >
C/C++ Source or Header  |  1993-08-01  |  8KB  |  200 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: CDLL.c
  4.     
  5.     BY     : Ronnie Yazma, Copyright 1993 GEOTEST Inc.   
  6.  
  7.     PURPOSE: Demonstarte None ATEasy type DLL functions.
  8.     
  9.     TO COMPILE:
  10.              Use CDLL.MAK when using Visual C/C++ v1.0 or MS-C 7.0
  11.              Use CDLL.PRJ when using Borland C/C++ v3.1     
  12.              This file compiled in large memory model.
  13.  
  14.     VERSION: 2.00 (Jul-26-93)
  15.  
  16.     FUNCTIONS/SUBROUTINES:
  17.  
  18.          - MaxSub() : finds the max between 2 floats
  19.          - MaxLongFunc() : return the max between 2 floats
  20.          - AverageArray() : find the avarage of float array
  21.          - NoSpaces() : delete leading & trailing spaces in a string
  22.          - UCase2Dim() : convert 2 dim string to upper case
  23.          
  24.     COMMENTS:
  25.            When using None ATEasy type DLL the parameters are passed from ATEasy
  26.            in the following way:
  27.            
  28.            ATEasy                   DLL                     Remarks
  29.            --------------------------------------------------------------------------
  30.            VAL Byte                 char                    BYTE also applicable
  31.            VAR Byte                 char FAR *
  32.            VAL Int                  short                   WORD also applicable (int and UINT in 16 bit DLLs)
  33.            VAR Int                  short FAR *
  34.            VAL Long                 long                    DWORD also applicable 
  35.            VAR Long                 long FAR *
  36.            VAL Float                double
  37.            VAR Float                double FAR *
  38.            VAL/VAR String[]         char FAR * or LPSTR     null terminated string
  39.            VAL/VAR String[,]        char FAR * FAR *        (array of pointers to strings)
  40.            VAL/VAR xxx [] or [,]    xxx FAR *               (xxx is Byte/Int/Long/Float)
  41.                       
  42.         Note that the calling convention is PASCAL.
  43.                       
  44. ****************************************************************************/
  45.  
  46. #include <windows.h>
  47. #include <string.h>     // for memmove 
  48. #include <ctype.h>      // for isspace, toupper 
  49.  
  50. #define _CALLBACK FAR PASCAL __export
  51.  
  52. /****************************************************************************
  53.    FUNCTION: LibMain(HANDLE, WORD, WORD, LPSTR)
  54.  
  55.    PURPOSE:  Is called by LibEntry.  LibEntry is called by Windows when
  56.              the DLL is loaded.  The LibEntry routine is provided in
  57.              the LIBENTRY.OBJ in the SDK Link Libraries disk.  (The
  58.              source LIBENTRY.ASM is also provided.)
  59.  
  60.              LibEntry initializes the DLL's heap, if a HEAPSIZE value is
  61.              specified in the DLL's DEF file.  Then LibEntry calls
  62.              LibMain.  The LibMain function below satisfies that call.
  63.  
  64.              The LibMain function should perform additional initialization
  65.              tasks required by the DLL.  In this example, no initialization
  66.              tasks are required.  LibMain should return a value of 1 if
  67.              the initialization is successful.                 
  68.              
  69.              Some compilers vendors provides LibMain in their static libraries
  70.              so you're allowed not to include this function.
  71.  
  72. ****************************************************************************/
  73. int FAR PASCAL LibMain(HINSTANCE hInstance, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
  74. {
  75.     return(1);
  76. }
  77.  
  78.  
  79. /****************************************************************************
  80.  
  81.     FUNCTION: WEP(int)
  82.  
  83.     PURPOSE:  Performs cleanup tasks when the DLL is unloaded.  WEP() is
  84.               called automatically by Windows when the DLL is unloaded (no
  85.               remaining tasks still have the DLL loaded). Some compilers vendors
  86.               provides WEP in their static libraries so you're allowed not to
  87.               include this function (if you don't need cleanup). If you're 
  88.               using MS-C it is much safer to use _WEP instead of WEP               .
  89.               The WEP should return 1.
  90.               
  91. ****************************************************************************/
  92. int FAR PASCAL WEP(int nExitType)
  93. {
  94.     return(1);
  95. }
  96.  
  97. /****************************************************************************
  98.  
  99.     FUNCTION: MaxSub(dX1, dX2, lpdResult)
  100.  
  101.     PURPOSE:  Finds the max of 2 floats (dX1 & dX2) into lpdResult.
  102.  
  103.        This subroutine defined in ATEasy as:
  104.        Max(fX1: VAL FLOAT, fX2: VAL FLOAT, fResult: VAR FLOAT): SUB DLL
  105.  
  106. ****************************************************************************/
  107. void _CALLBACK MaxSub(double dX1, double dX2, double FAR * lpdResult)
  108. {
  109.     *lpdResult=dX1 > dX2 ? dX1 : dX2;
  110. }
  111.  
  112. /****************************************************************************
  113.  
  114.     FUNCTION: MaxLongFunc(dX1, dX2)
  115.  
  116.     PURPOSE:  Returns the max of 2 longs (lX1 & lX2).
  117.               Note that this is a function. 
  118.  
  119.        This function defined in ATEasy as:
  120.        Long Max(lX1: VAL LONG, lX2: VAL LONG): Function DLL
  121.  
  122. ****************************************************************************/
  123. long _CALLBACK MaxLongFunc(long lX1, long lX2)
  124. {
  125.     return lX1 > lX2 ? lX1 : lX2;
  126. }
  127.  
  128. /****************************************************************************
  129.  
  130.     FUNCTION: AverageArray(lpdNumbers, nCount, lpdResult)
  131.  
  132.     PURPOSE:  Calculate the mean value of lpdNumbers array into lpdResult.
  133.  
  134.         This function defined in ATEasy as:
  135.         AverageArray(afNumbers : VAL FLOAT[], iCount : VAL Int, dResult : VAR FLOAT) : SUB DLL
  136.  
  137. ****************************************************************************/
  138. VOID _CALLBACK AverageArray(double FAR * lpdNumbers, short nCount, double FAR * lpdResult)
  139. {
  140.     double      dResult=0.0;
  141.     short       i;
  142.  
  143.     for (i=0; i < nCount; i++)
  144.         dResult+=lpdNumbers[i];
  145.     if (nCount)
  146.         dResult/=nCount;
  147.     *lpdResult=dResult;
  148. }
  149.  
  150. /****************************************************************************
  151.  
  152.     FUNCTION: NoSpaces(lpsz)
  153.  
  154.     PURPOSE:  Delete leading & trailing spaces in a string
  155.  
  156.         This function defined in ATEasy as:
  157.         NoSpaces(s : VAR String)
  158.  
  159. ****************************************************************************/
  160. VOID _CALLBACK NoSpaces(LPSTR lpsz)
  161. {
  162.     short       i, j;
  163.  
  164.     for (i=strlen(lpsz); i > 0; i--)           // delete trailing spaces
  165.         if (!isspace(lpsz[i-1])) break;
  166.     lpsz[i]=0;
  167.     for (j=0; j < i; j++)                      // delete leading spaces 
  168.         if (!isspace(lpsz[j])) break;
  169.     if (j)                                     // move to start 
  170.         memmove(lpsz, lpsz+j, strlen(lpsz));
  171. }
  172.  
  173. /****************************************************************************
  174.  
  175.     FUNCTION: UCase2Dim(lppsz, nCount)
  176.  
  177.     PURPOSE:  convert 2 dim string to upper case
  178.               nCount hold number of strings.
  179.  
  180.         This function defined in ATEasy as:
  181.         UCase2Dim(asStrings : VAR String[,], iCount VAL Int)
  182.  
  183. ****************************************************************************/
  184. VOID _CALLBACK UCase2Dim(char FAR * FAR * lppsz, short nCount)
  185. {
  186.     short       i, j, nLen;
  187.     LPSTR       lp;
  188.  
  189.     for (i=0; i < nCount; i++)
  190.     {   lp=lppsz[i];                              // get the i string
  191.         nLen=strlen(lp);                          // get the string length
  192.         for (j=0; j < nLen; j++)
  193.             lp[j]=toupper(lp[j]);                 // convert to upper case
  194.     }     
  195. }
  196.  
  197. /****************************************************************************
  198.                     E - O - F
  199. ****************************************************************************/
  200.